import datetime

from pydantic import BaseModel, Field
from typing import Optional, List

from module_admin.entity.vo.cms_driver_vo import DriverModel
from module_admin.entity.vo.cms_order_approve_vo import OrderApproveModel
from module_admin.entity.vo.cms_order_bill_vo import OrderBillModel
from module_admin.entity.vo.cms_order_execute_vo import OrderExecuteModel
from module_admin.entity.vo.cms_order_vo import OrderModel


class OrderDispatchModel(BaseModel):
    id: Optional[int] = Field(None, comment='主键')
    order_id: Optional[str] = Field(None, comment='单号')
    car_id: Optional[str] = Field(None, comment='车辆编码')
    driver_id: Optional[str] = Field(None, comment='驾驶员编码')
    state: Optional[int] = Field(None, comment='状态（1 未确认，2 已确认 3 退回）')
    reason: Optional[str] = Field(None, comment='拒绝原因')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    rading_count: Optional[int] = Field(None, comment='乘坐人数')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    confirm_time: Optional[datetime.datetime] = Field(None, comment='确认时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    # 额外
    driver_name: Optional[str] = Field(None, comment='驾驶员')
    driver_phone: Optional[str] = Field(None, comment='驾驶员电话')
    car_type: Optional[str] = Field(None, comment='车辆类型')

class OrderDispatchModel2(BaseModel):
    id: Optional[int] = Field(None, comment='主键')
    order_id: Optional[str] = Field(None, comment='单号')
    car_id: Optional[str] = Field(None, comment='车辆编码')
    driver_id: Optional[str] = Field(None, comment='驾驶员编码')
    state: Optional[int] = Field(None, comment='状态（1 未确认，2 已确认 3 退回）')
    reason: Optional[str] = Field(None, comment='拒绝原因')
    create_time: Optional[datetime.datetime] = Field(None, comment='创建时间')
    rading_count: Optional[int] = Field(None, comment='乘坐人数')
    create_by: Optional[str] = Field(None, comment='创建人')
    update_time: Optional[datetime.datetime] = Field(None, comment='修改时间')
    confirm_time: Optional[datetime.datetime] = Field(None, comment='确认时间')
    update_by: Optional[str] = Field(None, comment='修改人')
    # 额外
    driver_name: Optional[str] = Field(None, comment='驾驶员')
    driver_phone: Optional[str] = Field(None, comment='驾驶员电话')
    car_type: Optional[str] = Field(None, comment='车辆类型')
    car_number: Optional[str] = Field(None, comment='车牌号')

class OrderDispatchModelForCreateDriver(BaseModel):
    driver_id: Optional[str] = Field(None, title="驾驶员id 此处id为字母+id")
    car_id: Optional[str] = Field(None, title="车辆id 此处id为字母+id")

class OrderDispatchModelForCreate(BaseModel):
    id: Optional[int] = Field(None, title="id任务主键")
    driver_and_car: Optional[List[OrderDispatchModelForCreateDriver]] = Field(None, title="驾驶员id车辆id list集合 此处id为字母+id")


class OrderModelForDispatchDriver(BaseModel):
    id: Optional[int] = Field(None, title="id任务主键")
    operate: Optional[str] = Field(None, title="refuse(退回) confirm(确认) start(开始任务) end(完结)")
    reason: Optional[str] = Field(None, title="驳回理由")
    sign: Optional[str] = Field(None, title="签名")
    suspended_expenses: Optional[float] = Field(None, title="停延费")
    bill_type: Optional[str] = Field(None, title="结算类型 北斗系统结算 表显里程结算")
    start_mileage: Optional[float] = Field(None, comment='任务开始里程')
    end_mileage: Optional[float] = Field(None, comment='任务结束里程')
    start_file: Optional[str] = Field(None, comment='任务开始附件')
    end_file: Optional[str] = Field(None, comment='任务结束附件')


class OrderDetailsForDriverQuery(BaseModel):
    id: Optional[int] = Field(None, title="id用车申请id")
    operate: Optional[str] = Field(None, title="confirm(确认) start(开始任务) end(完结)")

class ConfirmModel(BaseModel):
    order_state: Optional[int] = Field(None, comment='任务状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）')
    remark: Optional[str] = Field(None, comment='备注')

class OperateModel(BaseModel):
    order_state: Optional[int] = Field(None, comment='任务状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）')
    confirm_time: Optional[datetime.datetime] = Field(None, comment='确认时间')
    driver_name: Optional[str] = Field(None, comment='驾驶员')

class OrderDetailsForDriver(BaseModel):
    order_details: Optional[OrderModel] = Field(None, title="用车信息")
    confirm_details: Optional[ConfirmModel] = Field(None, title="确认信息")
    operate_details: Optional[OperateModel] = Field(None, title="操作信息")


class DriverExecuteModel(BaseModel):
    state: Optional[int] = Field(None, comment='状态（1 未确认，2 已确认 3退回）')
    state_name: Optional[str] = Field(None, comment='状态（1 未确认，2 已确认 3退回）')
    remark: Optional[str] = Field(None, comment='备注')
    operate_time: Optional[datetime.datetime] = Field(None, comment='操作时间')
    confirm_time: Optional[datetime.datetime] = Field(None, comment='确认时间')

class OrderDetails(BaseModel):
    order_details: Optional[OrderModel] = Field(None, title="用车信息")
    order_approve_details: Optional[OrderApproveModel] = Field(None, title="审批信息")
    order_dispatch_details: Optional[OrderDispatchModel] = Field(None, title="调度信息")
    driver_details: Optional[DriverExecuteModel] = Field(None, title="驾驶员信息")
    order_execute_details: Optional[OrderExecuteModel] = Field(None, title="出车信息")
    order_bill_details: Optional[OrderBillModel] = Field(None, title="账单信息")
